//
//  RigisterVC.m
//  Running
//
//  Created by 郑东喜 on 2016/10/30.
//  Copyright © 2016年 郑东喜. All rights reserved.
//

#import "RigisterVC.h"
#import "LoginVC.h"
#import "MBProgressHUD+LJ.h"
#import "Encryption.h"
#import "MBManager.h"

@interface RigisterVC ()<CountDownDelegate,UITextFieldDelegate,CAAnimationDelegate,CommonToolDelegate>

@end

@implementation RigisterVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    
    self.seleImg.hidden = [stan boolForKey:rememChoose];
    NSLog(@"%s  %d  %zd",__func__,__LINE__,[stan boolForKey:rememChoose]);
    
    
    NSMutableAttributedString *content = [[NSMutableAttributedString alloc] initWithString:@"同意注册协议"];
    NSRange contentRange = {0, [content length]};
    
    [content addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:contentRange];
    
    self.agreeLabel.attributedText = content;
    
    [self.tfNum setTag:111];
    [self.tfPass setTag:112];
    [self.tfAuto setTag:113];
   
}

- (CountDown *)cBtn {
    if (!_cBtn) {
        _cBtn = [[CountDown alloc] init];
        
        _cBtn.delegate = self;
        //开始倒计时
        [_cBtn openCountdown];
    }
    return _cBtn;
}


#pragma mark - uitextfieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    
    switch (textField.tag) {
        case 111:
            [self.tfNum resignFirstResponder];
            [self.tfPass becomeFirstResponder];
            break;
        case 112:
            [self.tfPass resignFirstResponder];
            [self.tfAuto becomeFirstResponder];
            break;
        case 113:
            [self.tfAuto resignFirstResponder];
            break;
        default:
            break;
    }
    return YES;
}


- (IBAction)remChooseSEL:(UIButton *)sender {

    sender.selected = ![stan boolForKey:rememChoose];
    
    if (sender.isSelected) {
        self.seleImg.hidden = YES;
        [stan setBool:sender.isSelected forKey:rememChoose];
    } else {
        self.seleImg.hidden = NO;
        [stan setBool:sender.isSelected forKey:rememChoose];
    }

    [stan synchronize];
    

}


- (IBAction)rigSEL:(UIButton *)sender {
    
    [self.tools rigisterSELWithTFNum:self.tfNum withTFPass:self.tfPass withTFAuto:self.tfAuto];
}


- (IBAction)sendAutoNum:(CountDown *)sender {

    
    [self.tools setDelegate:self];
    
    [self.tools sendAutoSEL:self.tfNum];

    
   
}

- (IBAction)loginSEL:(id)sender {

    
    [self returnVC:[LoginVC new]];

}

- (IBAction)returnSEL:(id)sender {
    [self.navigationController pushViewController:[LoginVC new] animated:YES];
}

- (void)changeImgStatus:(CountDown *)countDonw {
    NSLog(@"%s  %d  %@",__func__,__LINE__,@"注册响应事件");
//    [self.seleImg setImage:[UIImage imageNamed:@"OK-2"]];
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        //主线程执行代码
        [self.sendAutoImg setImage:[UIImage imageNamed:@"btn_yzm02"]];
    });
}

#pragma mark - 代理回调
- (void)finishSetRigster:(CommonTool *)etRigsterSuccess {
    [self returnVC:[LoginVC new]];
    
}

- (void)finishSendMsg:(CommonTool *)sendMsgSuccess {
    
    [self cBtn];
    [self.sendAutoImg setImage:[UIImage imageNamed:@"sendSuccess"]];
}

@end
